/*
 *  Copyright (C) 2009  Peter Kist & Jan Ripke
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __gfx_ogre_manager_h
#define __gfx_ogre_manager_h 1

#include <boost/enable_shared_from_this.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>

#include <gfx/ogre/Types.h>

#include <core/Types.h>
#include <galaxy/ModuleManager.h>


namespace Ogre {
    class Root;
}

namespace galaxy {

    namespace mediator {
        class Event;
    }

    namespace gfx {
        namespace ogre3d {

            class GfxManagerThread;

            namespace engine {
                namespace galactic {
                    class GalaxyConsumer;
                }
            }


            /**
            * This class is the main entry point to the gfx module.
            * The implementation makes use of the Ogre 3D engine.
            * It embeds a Consumer and Producer so that it can be used by the mediator
            */
            class Manager : public boost::enable_shared_from_this<Manager>,
                public galaxy::ModuleManager
            {
                friend class GfxManagerThread;

                /** Recieve end-point for events */
                ProducerPtr        m_Producer;          
                /** Send end-point for events and handling queries */
                ConsumerPtr        m_Consumer;
                /** menu manager (CEGUI based) */
                MenuManagerPtr     m_MenuManager;
                /** the thread that handles all gfx functionality */
                GfxManagerThread * m_GfxManagerThread;

                // engine consumers (not shared_ptr's for now)
                engine::galactic::GalaxyConsumer * m_GalaxyConsumer;
                

                /** entry point to the OGRE engine */
                Ogre::Root * m_Root;

            public:
                Manager(void);
                virtual ~Manager(void);

                // ModuleManager interface
                virtual const char *    moduleName () { return "GFX Manager"; };
                virtual bool            initialize ();
                virtual bool            postInitialize ();
                virtual boost::thread * startManagerThread ();
                virtual void            terminateThread ();
                virtual bool            preDestroy ();
                virtual bool            destroy ();

                // ogre3d manager methods
                virtual void defineResources();
                virtual void setupRenderSystem();
                virtual void createRenderWindow();
                virtual void initializeResourceGroups();
                virtual void setupScene();
                virtual void setupInputSystem();
                virtual bool setupCEGUI();
                virtual void createFrameListener();

                virtual void terminate ();

                Ogre::Root*     getRoot ()                             { return m_Root;        };
                ConsumerPtr&    getConsumer ()                         { return m_Consumer;    };
                engine::galactic::GalaxyConsumer& getGalaxyConsumer () { return *m_GalaxyConsumer; };
                ProducerPtr&    getProducer ()                         { return m_Producer;    };
                MenuManagerPtr& getMenuManager ()                      { return m_MenuManager; };
            };

        } // namespace ogre3d
    } // namespace gfx
} // namespace galaxy

#endif // __gfx_ogre_manager_h
